package edu.uta.tsrh.db.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import edu.uta.tsrh.model.PendingFiles;
import java.sql.ResultSetMetaData;

public class PendingFilesMapper
    implements Mapper
{
    public PendingFilesMapper()
    {}


    public ArrayList<PendingFiles> map(ResultSet resultSet)
    {
        ArrayList<PendingFiles> pendingFilesList = new ArrayList<PendingFiles>();
        try
        {   // resultSet.last(); // position on last row
         //int rowcnt = resultSet.getRow(); // get row no.
        // resultSet.beforeFirst(); // reposition on 1st row
     
         //for(int q=0; q<rowcnt; q++) {
           
            while (resultSet.next())
            {
                PendingFiles pendingFile = new PendingFiles();
                pendingFile.setFileId((String) resultSet.getString("file_id"));

                pendingFile.setPatientFirstName((String) resultSet.getString("p_first"));
                pendingFile.setPatientLastName((String) resultSet.getString("p_last"));
                
                pendingFile.setReason((String) resultSet.getString("reason"));
                pendingFile.setPendingLoaction((String) resultSet.getString("location"));                
                pendingFile.setPendingDate((Timestamp) resultSet.getTimestamp("MAX(pd.return_date)"));
                pendingFile.setEmployeeName((String) resultSet.getString("usr_first") + " "
                    + (String) resultSet.getString("usr_last"));
                pendingFilesList.add(pendingFile);
            }
      //  }
         
        }
        catch (SQLException e)
        {
            e.printStackTrace();
        }
        finally
        {
            try
            {
                resultSet.close();
            }
            catch (SQLException e)
            {
                e.printStackTrace();
            }
        }
        return pendingFilesList;
    }
}
